package com.atguigu.srb.core.controller.admin;

import com.atguigu.srb.base.util.JwtUtils;
import com.atguigu.srb.core.pojo.entity.BorrowInfo;
import com.atguigu.srb.core.pojo.vo.BorrowInfoApprovalVO;
import com.atguigu.srb.core.result.R;
import com.atguigu.srb.core.service.BorrowInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin/core/borrowInfo")
@Api(tags = "借款人信息管理")
@Slf4j
public class AdminBorrowInfoController {
    @Autowired
    BorrowInfoService borrowInfoService;


    @ApiOperation("借款信息列表")
    @GetMapping("/list")
    public R list(HttpServletRequest request) {
        List<BorrowInfo> borrowInfoList = borrowInfoService.selectBorrowInfoList();
        return R.ok().data("borrowInfoList", borrowInfoList);

    }

    @ApiOperation("借款信息详情")
    @GetMapping("/show/{borrowInfoId}")
    public R show(@PathVariable("borrowInfoId") Long borrowInfoId, HttpServletRequest request) {
        log.info("借款信息详情--->>>" + borrowInfoId);
        Map<String, Object> borrowerInfoDetail = borrowInfoService.showBorrowInfo(borrowInfoId);
        return R.ok().data("borrowerInfoDetail", borrowerInfoDetail);
    }

    @ApiOperation("借款审批")
    @PostMapping("/approval")
    public R approvalSubmit(@RequestBody BorrowInfoApprovalVO borrowInfoApprovalVO) {
        log.info("借款审批--->>>"+borrowInfoApprovalVO.toString());
        borrowInfoService.approvalSubmit(borrowInfoApprovalVO);
        return R.ok().message("借款审批成功");
    }


}
